<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <style>
        #box{width:255px;height:20px;list-style: none;}
        #box li{float:left;line-height: 20px;width:49px;border:1px #000 solid;text-align: center;cursor: pointer;}
    </style>
    <ul id="box">
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
    <script>
        var box = document.getElementById('box'),
        liTag = box.getElementsByTagName('li'),
        length = liTag.length,
        i = 0;
        for(;i<length;i++){
            liTag[i].onclick = (function(i){
                return function(){
                    alert(i);
                }
            })(i);
        }
    </script>

</body>
</html>